package glue_srvp

import (
	"context"
	"gluenet/internal/glue-srvp/adapter/iris-controller"
	"gluenet/internal/glue-srvp/adapter/metrics-cli"
	"gluenet/internal/glue-srvp/adapter/nats-cli"
	"gluenet/internal/glue-srvp/adapter/nats-controller"
	"gluenet/internal/glue-srvp/adapter/repository"
	"gluenet/internal/glue-srvp/adapter/rest-cli"
	"gluenet/internal/glue-srvp/adapter/syncer"
	"gluenet/internal/pkg/infra/prepare"
)

func Run(ctx context.Context) {
	prepare.Register()

	// fisrt register repo
	if err := repository.Install(); err != nil {
		panic(err)
	}

	// then register bottom dependency cli
	if err := metrics_cli.Install(); err != nil {
		panic(err)
	}
	if err := nats_cli.Install(); err != nil {
		panic(err)
	}
	if err := rest_cli.Install(); err != nil {
		panic(err)
	}

	// next register top dependency controller
	if err := iris_controller.Install(); err != nil {
		return
	}
	if err := nats_controller.Install(); err != nil {
		return
	}

	//finally register syncer daemon
	if err := syncer.Install(ctx); err != nil {
		panic(err)
	}
}
